﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.Web.Base;
using OASys.Web.Areas.ModuleWF.Models;
using Project.Web.Base.Utility;
using Project.Common;
using OASys.Biz.BizAccess;

namespace OASys.Web.Areas.ModuleWF.Controllers
{
	public class WorkFlowController : BaseController
	{
		public BizWFFlow bizWFFlow;
		//
		// GET: /ModuleWF/WorkFlow/

		public ActionResult Index(ModelWorkFlowIndex model, ExportHelper export)
		{
			model.RetriveData();
			return View(model);
		}

		public ActionResult Create(Guid? id, EnumPageState? pageState)
		{
			ViewBag.PageState = GetPageState(id, pageState);
			if (id != null)
			{
				ModelWorkFlowCreate model = new ModelWorkFlowCreate();
				model.WFFlow = bizWFFlow.GetByID<Guid>(id.Value);
				return View(model);
			}
			return View();
		}

		[HttpPost]
		public ActionResult Create(ModelWorkFlowCreate model)
		{
			try
			{
				model.Save();
				return Content(WebTools.ScriptCloseDialog(DialogOption.GetDefaultInstance()));
			}
			catch
			{
				Error = "操作失败";
				ViewBag.PageState = PageState;
				return View(model);
			}
		}

		[HttpPost]
		public ActionResult Delete(Guid id)
		{
			JsonResult jsresult = new JsonResult();
			jsresult.ContentType = Consts.CONTENT_TYPE;
			try
			{
				bizWFFlow.DeleteByID(id, NHibernate.NHibernateUtil.Guid);
				jsresult.Data = new { result = string.Empty };
			}
			catch
			{
				jsresult.Data = new { result = "操作失败" };
			}
			return jsresult;
		}

	}
}
